package com.dd;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.chantel.tool.db.DBUtil;

public class XiaLaLiebiaoInfos {
	
	////////////////////////////////////////////
	//常用   单位  操作
	////////////////////////////////////////////
	//
	//返回所有常用的单位
	//
	public static Map GetAllDanWei()
	{
		DBUtil du = DBUtil.getInstance();
		
		Map mIdToDanWei = new HashMap();
		
		String sql = "select* from ShangPingDanWeiTable";
		
		List l = du.getRecords(sql);
		Iterator itr = l.iterator();
		while (itr.hasNext()) {
			Map m1 = (Map) itr.next();
			
			String id =  Integer.toString(((Integer) m1.get("Id")).intValue());
			String danWei = (String)m1.get("ShangPingDanWei");
			
			mIdToDanWei.put(id, danWei);
		}
		
		
		return mIdToDanWei;
	}
	//
	//添加新的单位
	//
	public boolean AddDanWei(String strNewDanWei)
	{
		
		DBUtil du = DBUtil.getInstance();
		Map m = new HashMap();
		m.put("ShangPingDanWei", strNewDanWei);
		
		boolean bool_res = du.insertRecord("ShangPingDanWeiTable", m);
		return bool_res;

	}
	
	//
	//更新单位
	//
	public boolean UpdateDanWei(String id,String newDanWei)
	{
		DBUtil du = DBUtil.getInstance();
		Map m = new HashMap();
		
		m.put("ShangPingDanWei", newDanWei);


		String updateWhere = "Id=" + id;
		
		boolean bool_res = du.updateFieldsValue("ShangPingDanWeiTable", m,
				updateWhere);
		
		return bool_res;
		
	}
	//
	//删除单位
	//
	public boolean DeleteDanWei(String id)
	{
		DBUtil du = DBUtil.getInstance();

		String sql = "delete from ShangPingDanWeiTable where Id = "
				+ id;

		boolean bool_res = du.deleteRecords(sql);

		return bool_res;
	}
	
	////////////////////////////////////////////////
	//常用  类别 操作
	///////////////////////////////////////////////
	//
	//返回所有常用的类别
	//
	public static Map GetAllLeiBie()
	{
		DBUtil du = DBUtil.getInstance();
		
		Map mIdToLeiBie = new HashMap();
		
		String sql = "select* from XiangMuLeiBieTable";
		
		List l = du.getRecords(sql);
		Iterator itr = l.iterator();
		while (itr.hasNext()) {
			Map m1 = (Map) itr.next();
			
			String id =  Integer.toString(((Integer) m1.get("Id")).intValue());
			String leiBie = (String)m1.get("XiangMuLeiBie");
			
			mIdToLeiBie.put(id, leiBie);
		}
		
		
		return mIdToLeiBie;
	}
	
	//
	//添加新的类别
	//
	public boolean AddLeiBie(String strNewLeiBie)
	{		
		DBUtil du = DBUtil.getInstance();
		Map m = new HashMap();
		m.put("XiangMuLeiBie", strNewLeiBie);
		
		boolean bool_res = du.insertRecord("XiangMuLeiBieTable", m);
		return bool_res;
	
	}
	
	//
	//更新类别
	//
	public boolean UpdateLeiBie(String id,String newLeiBie)
	{
		DBUtil du = DBUtil.getInstance();
		Map m = new HashMap();
		
		m.put("XiangMuLeiBie", newLeiBie);


		String updateWhere = "Id=" + id;
		
		boolean bool_res = du.updateFieldsValue("XiangMuLeiBieTable", m,
				updateWhere);
		
		return bool_res;
		
	}
	//
	//删除类别
	//
	public boolean DeleteLeiBie(String id)
	{
		DBUtil du = DBUtil.getInstance();

		String sql = "delete from XiangMuLeiBieTable where Id = "
				+ id;

		boolean bool_res = du.deleteRecords(sql);

		return bool_res;
		
	}
	
	//////////////////////////////////////////////////////////
	//常用  意见  操作
	/////////////////////////////////////////////////////////
	
	//
	//返回所有常用的意见
	//
	public static Map GetAllYiJian()
	{	
		DBUtil du = DBUtil.getInstance();
		
		Map mIdToYiJian= new HashMap();
		
		String sql = "select* from YiJianTable";
		
		List l = du.getRecords(sql);
		Iterator itr = l.iterator();
		while (itr.hasNext()) {
			Map m1 = (Map) itr.next();
			
			String id =  Integer.toString(((Integer) m1.get("Id")).intValue());
			String danWei = (String)m1.get("YiJian");
			
			mIdToYiJian.put(id, danWei);
		}
		
		
		return mIdToYiJian;
	}
	//
	//添加新的意见
	//
	public boolean AddYiJian(String strNewYiJian)
	{
		DBUtil du = DBUtil.getInstance();
		Map m = new HashMap();
		m.put("YiJian", strNewYiJian);
		
		boolean bool_res = du.insertRecord("YiJianTable", m);
		return bool_res;
	
	}
	
	//
	//更新意见
	//
	public boolean UpdateYiJian(String id,String newYiJian)
	{
		
		DBUtil du = DBUtil.getInstance();
		Map m = new HashMap();
		
		m.put("YiJian", newYiJian);


		String updateWhere = "Id=" + id;
		
		boolean bool_res = du.updateFieldsValue("YiJianTable", m,
				updateWhere);
		
		return bool_res;
		
	}
	//
	//删除意见
	//
	public boolean DeleteYiJian(String id)
	{
		DBUtil du = DBUtil.getInstance();

		String sql = "delete from YiJianTable where Id = "
				+ id;

		boolean bool_res = du.deleteRecords(sql);

		return bool_res;
		
	}
	/**
	 * 为下列表生成option html代码
	 * @param m
	 * @return
	 */
	public static String getHtmlOption(Map m){
		StringBuffer b_str = new StringBuffer("");
		Set s = m.keySet();
		Iterator it = s.iterator();
		while (it.hasNext()) {
			String key = (String) it.next();

			if (key != null) {
				String val = (String) m.get(key);
				b_str.append("<option value=\"" + val + "\">" + val
				+ "</option>");
			}
		}
		return b_str.toString();
	}

	
	public static Map getXiangMuLeiBieByID(int id){
		String sql = "select * from XiangMuLeiBieTable";
		Map whereFields = new HashMap();
		whereFields.put( "Id", new Integer(id) );
		DBUtil2 db2 = DBUtil2.getDefaultDBUtil2();
		Map m = db2.getRow(sql, whereFields);
		return m;
	}
}
